/*
 * @Description: 聊天相关全局状态管理
 * @Author: Wenguang Song
 * @Date: 2022-04-29 15:22
 * @LastEditors: Wenguang Song
 * @LastEditTime: 2022-05-28 16:26
 * @FilePath: /call_service/src/store/modules/im.js
 */
import { Message } from 'element-ui'
import Vue from 'vue'
const state = {
  agentNo: '',
  tenantId: '',
  // 座席相关
  sittable: {
    call_active: '', //通话状态，来电-通话中-拨号中-转接中
    callStatus: 'busy', // 示闲状态，ready：就绪，idle：示闲， busy：示忙
    mediaStatus: 'busy',
  },
  // 统计相关
  statistic: {
    call_queue_count: 0, // 电话队列
    call_miscall_count: 0, // 未接数
    media_queue_count: 0, // 留言队列
    media_leavemsg_count: 0, // 留言数
  },
}

const mutations = {
  // 获取坐席初始状态
  SOCKET_MEDIA_statusready(state, data) {
    state.sittable.mediaStatus = data.mediaStatus
  },
  SOCKET_CALL_statusready(state, data) {
    state.sittable.callStatus = data.callStatus
  },
  // 排队、留言
  SOCKET_MEDIA_report(state, data) {
    if (data.mediaQueueCount) {
      state.statistic.media_queue_count = data.mediaQueueCount
    }
    if (data.mediaLeavemsgCount) {
      state.statistic.media_leavemsg_count = data.mediaLeavemsgCount
    }
  },
  SOCKET_CALL_report(state, data) {
    if (data.callQueueCount) {
      state.statistic.call_queue_count = data.callQueueCount
    }
    if (data.callMiscallCount) {
      state.statistic.call_miscall_count = data.callMiscallCount
    }
  },
  // 多媒体上班、示忙、示闲
  // 错误情况二期处理
  SOCKET_MEDIA_status(state, data) {
    Message[data.code === '100000' ? 'success' : 'error'](data.data)
  },

  // 电话上班、示忙、示闲
  // 错误情况二期处理
  SOCKET_CALL_status(state, data) {
    Message[data.code === '100000' ? 'success' : 'error'](data.data)
  },
  SOCKET_MEDIA_ping(state, data) {
    // console.log('ping事件处理=========',data, this.$sockets)
    // const mediaStatus = store.state.im.sittable.mediaStatus
    // mediaSocket.io.emit('statusSync', mediaStatus)
  },
  SET_AgentNo(state, data) {
    state.agentNo = data
  },
  SET_TenantId(state, data) {
    state.tenantId = data
  },
}

const actions = {
  // TODO: DEMO
  // closeSideBar({ commit }, { withoutAnimation }) {
  //   commit('CLOSE_SIDEBAR', withoutAnimation)
  // },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
